﻿using System;
using System.ServiceModel;

using BLToolkit.Reflection;

using EMan.Server.DependencyInjection;
using EMan.Server.DependencyInjection.Scoping;
using EMan.Server.WCF;

namespace EMan.Server
{
  static class Program
  {
    private static readonly ServerFactory _di = new ServerFactory( GlobalScopeContainerProvider.GetContainer() );

    static void Main()
    {
      try
      {
        using( var serviceHost = new ServiceHost( TypeAccessor< EManService >.Type ) )
        //using( var serviceHost = new ServiceHost( typeof( EManServicePlain ) ) )
        {
          serviceHost.Description.Behaviors.Add( new InstanceProviderBehavior( () => _di.Resolve< EManService >() ) );
          //serviceHost.Description.Behaviors.Add( new InstanceProviderBehavior( () => _di.Container.Resolve< EManServicePlain >() ) );
          serviceHost.Faulted += ( s, e ) => Console.WriteLine( e );

          serviceHost.Open();
          
         
          Console.WriteLine( "ServiceHost started" );
          Console.ReadLine();
          serviceHost.Close();
        }
      }
      catch( Exception e )
      {
        Console.WriteLine( e );
      }
      Console.WriteLine( "ServiceHost stopped" );
      Console.WriteLine( "Press ENTER to exit" );
      Console.ReadLine();
    }
  }
}
